/**
 * 获取localStorage
 */
export const getStorage = key =>{ 
   if(!key) return;
   return window.localStorage.getItem(key);
}

/**
 * 存储localStorage
 */
export const setStorage = (key,name) => {
  if(!name) return;
  if(typeof name === 'String'){
      name = JSON.stringify(name);
  }
  window.localStorage.setItem(key,name);
}

/**
 * 删除localStorage
 */
export const removeStorage = key => {
  if(!key) return;
  return window.localStorage.removeItem(key);
}

/**
 * 公共的setlocalStorage方法
 */
export const saveToLocall = (id,key,value) => {
  let seller = window.localStorage._seller_;//_seller_表示私有变量
  if(!seller){
    seller = {};
    seller[id] = {}; //{ _seller_:{"12":{"favorite":true},"12345":{"favorite":true}} }
  }else {
    seller = JSON.parse(seller); //字符串转换成对象
    if(!seller[id]){ //判断seller[id]而不是seller
      seller[id] = {}
    }
  }
    seller[id][key] = value;
    window.localStorage._seller_ = JSON.stringify(seller);
}

export const loadFromLocal = (id,key,def) => {
  let seller = window.localStorage._seller_;
  if(!seller){
    return def;
  }else {
    seller = JSON.parse(seller)[id];
    if(!seller) { //判断seller[id]而不是seller
      return def;
    }
    return seller[key] || def;
  }
}